package java3_29;

import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

/**
 * 4：输出今年的星期天都是几号
 */
public class HomeWork4 {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
//        LocalDate now = LocalDate.now();
//        int year = now.getYear();
//        int month = now.getMonthValue();
//
//        for (int day = 1; day <= 31; day++) {
//            LocalDate date = LocalDate.of(year, month, day);
//            DayOfWeek dayOfWeek = date.getDayOfWeek();
//
//            if (dayOfWeek == DayOfWeek.SUNDAY) {
//                System.out.println("This year's Sunday is on the " + day + "th day of the month.");
//            }
//        }
        int year = c.get(Calendar.YEAR);
        c.set(year,Calendar.JANUARY,1);//本年的一月一号
        int w = 0;
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week!= Calendar.SUNDAY)
         w = 7+1-c.get(Calendar.DAY_OF_WEEK);
        c.add(Calendar.DATE,w);
        while (c.get(Calendar.YEAR)==year){
            Date d = c.getTime();
            String s1 = s.format(d);
            System.out.println("周日:" + s1);
            c.add(Calendar.DATE,7);
        }
    }
}
